/*

Siwei Cheng	
Proposal title: Understanding Public Perceptions of Absolute and Relative Social Mobility

HYPOTHESES

Stated-Hyp1: We hypothesize that these vignettes (college education vs. hardwork) may
	generate varying public perceptions of mobility chances. 

	Test-Hyp1: The association between parent rank (treatment) and child's rank (predicted by the respondent) will systematically vary if the vigenette specifies that the child went to college vs. the child is a hard worker.
	
Stated-Hyp2: The effects of education vs. hard work may differ between perceptions of 
	absolute and relative mobility.

	// can't test - see note
	
Stated-Hyp3: [Unclear - authors had some survey items that they planned to compare to estimates from Chetty et al.]
	
	// Takes more than 15 minutes to get external data.
	
********************************************************************************
NOTES:

- The analysis plan on page 2 of proposal describes how relative and absolute mobility are defined: 
First, regressing the child's rank on parent's rank provides estimate of percieved rank-rank assoication.
		- Percieved absolute mobility: child's predicted rank given parent rank
		- Percieved relative mobility: slope of the rank-rank association line

- We can calculate both percieved relative and absolute mobility as the proposal 
defines them. But in order to test hypothesis 2, we will need to compare the two types of 
percieved mobility. Not sure how to pursue that. 
	*/

clear all
use "ChengS15.dta", clear

********************************************************************************

* INDICATORS OF EXPERIMENTAL MANIPULATIONS

* Treatment

	/*
The proposal specifies 3 treatment groups (including control) but the data has 4 treatment groups. 
Questionnaire shows that groups 1 and 2 are controls and 3 and 4 are treatments (college and hard work, respectively.)
However, group 2 is also shown extra information about mobility in the US. No other group is shown that info.
I'm not sure why group 2 was included (not explained in proposal). I'm excluding group 2 from the analysis.
*/

	tab P_CONDITION
	recode P_CONDITION (1=1) (2=.) (3=2) (4=3), gen(child_quality)
	lab def condition 1	"1 control" 2 "2 college" 3 "3 hardworker" 
	lab val child_quality condition
	tab child_quality, mis
	

	
* parent rank shown in each question
	/* From quex:
	
	- for each treatment condition, 3 random percentiles are chosen, and 
	the question is looped 3 times with one of the random percentiles.
	*/
	
	gen parentrank1 =. 
	gen parentrank2 =.
	gen parentrank3 =.
	
	forval j=1/4 {
	replace parentrank1=Q`j'PrcntShownFrst if P_CONDITION==`j'
	replace parentrank2=Q`j'PrcntShownSnd if P_CONDITION==`j'
	replace parentrank3=Q`j'PrcntShownTrd if P_CONDITION==`j'
	}
	
	foreach var of varlist parentrank* {
	tab `var'
	}

* CONSTRUCT OUTCOME MEASURES

* expected rank of child
	/* combining answers to q1 through 3 for each of the 4 treatments
	*/
	
	gen childrank1=.
	gen childrank2=.
	gen childrank3=.
	
	forval j=1/4 {
	replace childrank1=Q`j'_1 if P_CONDITION==`j'
	replace childrank2=Q`j'_2 if P_CONDITION==`j'
	replace childrank3=Q`j'_3 if P_CONDITION==`j'
	}
	
	foreach var of varlist childrank* {
	replace `var'=. if `var'>100
	tab `var'
	}

* RESHAPE
// reshape file to long
	/* since each R gets the same treatment 3 times, we can reshape such that
	each case (i.e. fictitious person) is a unique observation
	*/
reshape long childrank parentrank, i(CaseId) j(loop)
	
********************************************************************************

* ANALYSIS
	
	*Test-Hyp1: The association between parent rank (treatment) and child's rank (predicted by the respondent) will systematically vary if the vigenette specifies that the child went to college vs. the child is a hard worker.
		
	reg childrank c.parentrank##i.child_quality if child_quality!=1, vce(cluster CaseId)
		// excluding control condition b/c hypothesized comparison is between college vs. hardwork
	
	// reject. p: 0.100. 
	
	tess parentrank#3.child_quality, init(ChengS15)
